<!-- 主页的页面 -->
<template>
    <!-- 引入这个containner布局 -->
    <el-container class="home_container">
        <!-- 头部 -->
        <el-header class="el-header">
            <div>
                <img src="../assets/logo.png" alt="显示的一个logo" />
                <span>数据挖掘综合实验</span>
            </div>
            <el-dropdown @command="handleCommand" split-button type="primary">
                {{ username }}
                <el-dropdown-menu slot="dropdown">
                    <el-dropdown-item command="a">首页</el-dropdown-item>
                    <el-dropdown-item command="c">退出</el-dropdown-item>
                </el-dropdown-menu>
            </el-dropdown>
        </el-header>
        <!-- 中间和这个侧边栏 -->
        <el-container>
            <el-aside :width="collapse ? '64px' : '200px'" class="el-aside">
                <div class="toggle-button" @click="toggleNav">|||</div>

                <!-- 在这个地方动态绑定的时候,才可以使用这个js里面的数据的类型 -->
                <el-menu
                    background-color="#545c64"
                    text-color="#fff"
                    @open="handleOpen"
                    active-text-color="#409eff"
                    :collapse="collapse"
                    :collapse-transition="false"
                    unique-opened
                    :router="true"
                    :default-active="activePath"
                >
                    <!-- 系统管理,用户来进行设置的来进行编写的-->
                    <!-- <el-submenu index="2" key="2" v-show="author.indexOf('admin') >= 0">
            <template slot="title">
              <i class="el-icon-s-tools"></i>
              <span>系统管理</span>
            </template>

            <el-menu-item
              index="/userManage"
              key="2-1"
              @click="saveActivePath('/userManage')"
            >
              <template slot="title">
                <i class="el-icon-user"></i>
                <span>用户管理</span>
              </template>
            </el-menu-item>
          </el-submenu> -->

                    <el-submenu index="3" key="3">
                        <template slot="title">
                            <i class="el-icon-user-solid"></i>
                            <span>关联规则</span>
                        </template>

                        <el-submenu index="3-1">
                            <template slot="title">实验一</template>
                            <el-menu-item
                                index="/aExp1Show"
                                key="3-1-1"
                                @click="saveActivePath('/aExp1Show')"
                            >
                                <template slot="title">
                                    <i class="el-icon-reading"></i>
                                    <span>实验介绍</span>
                                </template>
                            </el-menu-item>
                            <el-menu-item
                                index="/aExp1DataShow"
                                key="3-1-2"
                                @click="saveActivePath('/aExp1DataShow')"
                            >
                                <template slot="title">
                                    <i class="el-icon-reading"></i>
                                    <span>数据集</span>
                                </template>
                            </el-menu-item>
                            <el-menu-item
                                index="/aExp1DataAnswer"
                                key="3-1-3"
                                @click="saveActivePath('/aExp1DataAnswer')"
                            >
                                <template slot="title">
                                    <i class="el-icon-reading"></i>
                                    <span>实验结果</span>
                                </template>
                            </el-menu-item>
                        </el-submenu>
                        <el-submenu index="3-2">
                            <template slot="title">实验二</template>
                            <el-menu-item
                                index="/aExp2Show"
                                key="3-2-1"
                                @click="saveActivePath('/aExp2Show')"
                            >
                                <template slot="title">
                                    <i class="el-icon-reading"></i>
                                    <span>实验介绍</span>
                                </template>
                            </el-menu-item>
                            <el-menu-item
                                index="/aExp2DataShow"
                                key="3-2-2"
                                @click="saveActivePath('/aExp2DataShow')"
                            >
                                <template slot="title">
                                    <i class="el-icon-reading"></i>
                                    <span>获取数据集</span>
                                </template>
                            </el-menu-item>
                            <el-menu-item
                                index="/aExp2OtherData"
                                key="3-2-3"
                                @click="saveActivePath('/aExp2OtherData')"
                            >
                                <template slot="title">
                                    <i class="el-icon-reading"></i>
                                    <span>获取频繁项集和关联规则</span>
                                </template>
                            </el-menu-item>
                            <el-menu-item
                                index="/aExp2Detail"
                                key="3-2-4"
                                @click="saveActivePath('/aExp2Detail')"
                            >
                                <template slot="title">
                                    <i class="el-icon-reading"></i>
                                    <span>获取中间过程</span>
                                </template>
                            </el-menu-item>
                            <el-menu-item
                                index="/aExp2Pic"
                                key="3-2-5"
                                @click="saveActivePath('/aExp2Pic')"
                            >
                                <template slot="title">
                                    <i class="el-icon-reading"></i>
                                    <span>获取热力图</span>
                                </template>
                            </el-menu-item>
                        </el-submenu>
                    </el-submenu>

                    <el-submenu index="4" key="4">
                        <template slot="title">
                            <i class="el-icon-user-solid"></i>
                            <span>聚类分析</span>
                        </template>
                        <el-submenu index="4-2">
                            <template slot="title">实验一</template>
                            <el-menu-item
                                index="/bExp1Show"
                                key="4-2-1"
                                @click="saveActivePath('/bExp1Show')"
                            >
                                <template slot="title">
                                    <i class="el-icon-reading"></i>
                                    <span>实验介绍</span>
                                </template>
                            </el-menu-item>
                            <el-menu-item
                                index="/bExp1DataShow"
                                key="4-2-2"
                                @click="saveActivePath('/bExp1DataShow')"
                            >
                                <template slot="title">
                                    <i class="el-icon-reading"></i>
                                    <span>获取数据集</span>
                                </template>
                            </el-menu-item>
                            <el-menu-item
                                index="/bExp1Kmeans"
                                key="4-2-3"
                                @click="saveActivePath('/bExp1Kmeans')"
                            >
                                <template slot="title">
                                    <i class="el-icon-reading"></i>
                                    <span>kmeans分类</span>
                                </template>
                            </el-menu-item>
                            <el-menu-item
                                index="/bExp1Dbscan"
                                key="4-2-4"
                                @click="saveActivePath('/bExp1Dbscan')"
                            >
                                <template slot="title">
                                    <i class="el-icon-reading"></i>
                                    <span>dbscan分类</span>
                                </template>
                            </el-menu-item>
                        </el-submenu>

                        <el-submenu index="4-3">
                            <template slot="title">实验二</template>
                            <el-menu-item
                                index="/bExp2Show"
                                key="4-3-1"
                                @click="saveActivePath('/bExp2Show')"
                            >
                                <template slot="title">
                                    <i class="el-icon-reading"></i>
                                    <span>实验介绍</span>
                                </template>
                            </el-menu-item>
                        </el-submenu>
                    </el-submenu>

                    <el-submenu index="5" key="5">
                        <template slot="title">
                            <i class="el-icon-user-solid"></i>
                            <span>分类模型</span>
                        </template>
                        <el-submenu index="5-2">
                            <template slot="title">实验一</template>

                            <el-menu-item
                                index="/cExp1Show"
                                key="5-2-1"
                                @click="saveActivePath('/cExp1Show')"
                            >
                                <template slot="title">
                                    <i class="el-icon-reading"></i>
                                    <span>实验介绍</span>
                                </template>
                            </el-menu-item>

                            <el-menu-item
                                index="/cExp1DataShow"
                                key="5-2-2"
                                @click="saveActivePath('/cExp1DataShow')"
                            >
                                <template slot="title">
                                    <i class="el-icon-reading"></i>
                                    <span>获取数据集</span>
                                </template>
                            </el-menu-item>
                            <el-menu-item
                                index="/cExp1ResultPic"
                                key="5-2-3"
                                @click="saveActivePath('/cExp1ResultPic')"
                            >
                                <template slot="title">
                                    <i class="el-icon-reading"></i>
                                    <span>结果图</span>
                                </template>
                            </el-menu-item>
                        </el-submenu>
                    </el-submenu>

                    <el-submenu index="6" key="6">
                        <template slot="title">
                            <i class="el-icon-user-solid"></i>
                            <span>回归模型</span>
                        </template>

                        <el-submenu index="6-2">
                            <template slot="title">实验一</template>

                            <el-menu-item
                                index="/dExp1Show"
                                key="6-2-1"
                                @click="saveActivePath('/dExp1Show')"
                            >
                                <template slot="title">
                                    <i class="el-icon-reading"></i>
                                    <span>实验介绍</span>
                                </template>
                            </el-menu-item>
                            <el-menu-item
                                index="/dExp1DataShow"
                                key="6-2-2"
                                @click="saveActivePath('/dExp1DataShow')"
                            >
                                <template slot="title">
                                    <i class="el-icon-reading"></i>
                                    <span>获取数据集</span>
                                </template>
                            </el-menu-item>
                            <el-menu-item
                                index="/dExp1Pic1"
                                key="6-2-3"
                                @click="saveActivePath('/dExp1Pic1')"
                            >
                                <template slot="title">
                                    <i class="el-icon-reading"></i>
                                    <span>一元回归图片</span>
                                </template>
                            </el-menu-item>
                            <el-menu-item
                                index="/dExp1Pic2"
                                key="6-2-4"
                                @click="saveActivePath('/dExp1Pic2')"
                            >
                                <template slot="title">
                                    <i class="el-icon-reading"></i>
                                    <span>二元回归图片</span>
                                </template>
                            </el-menu-item>
                        </el-submenu>
                    </el-submenu>
                    <!-- 这个id的绑定主要就是为了设置这个点击的时候,这个颜色的不变化,然后在这个设置的一个东西 -->
                </el-menu>
            </el-aside>
            <el-main class="el-main">
                <router-view></router-view>
            </el-main>
        </el-container>
    </el-container>
    <!-- <div>
      <el-button type="info"  @click="logout">安全退出</el-button>
  </div> -->
</template>

<script>
export default {
    name: "Home",
    data() {
        return {
            //菜单列表
            // menuList: [],
            collapse: false,
            username: "",
            author: "",
            activePath: "/welcome", //或多这个路由
        };
    },
    created() {
        this.getUserName(); //得到的一个用户的一个名称
        this.activePath = window.sessionStorage.getItem("activePath"); //得到之前以一个访问的一个路径
        // this.author = JSON.parse(window.sessionStorage.getItem("user")) //代表当前的一个角色的信息
        //     .authorities.map((obj, index) => {
        //         return obj.authority;
        //     })
        //     .join(",");
    },
    // 因为在这个地方我们是一进来就需要访问的一个方法,那么就需要放到这个create方法里面,就是类似于这个onload事件,那么就是需查询这个meanulist
    methods: {
        async logout() {
            window.sessionStorage.clear(); //清楚这个用户的信息，然后就可以完全安装这个流程。
            this.$message.warning("登出成功！"); //信息的提示
            this.$router.push("login"); //这个就是转到这个登录的页面
        },
        handleOpen(key, keypath) {
            switch (key) {
                case "3":
                    this.$router.push("association");
                    break;
                case "4":
                    this.$router.push("cluster");
                    break;
                case "5":
                    this.$router.push("classification");
                    break;
                case "6":
                    this.$router.push("regression");
                    break;
            }
        },
        handleCommand(command) {
            switch (command) {
                case "c":
                    this.logout();
                    break;
                case "a":
                    this.$router.push("association"); //首页跳转到这个welcom组件上面
                    break;
                default:
                    break;
            }
        },
        getUserName() {
            this.username = JSON.parse(
                window.sessionStorage.getItem("user")
            ).name;
        },
        toggleNav() {
            this.collapse = !this.collapse; //控制伸缩
        },
        saveActivePath(path) {
            //保存这个访问的路径
            this.activePath = path;
            window.sessionStorage.setItem("activePath", path); //放到这个session里面,
        },
    },
};
</script>

<style lang="less"  scoped>
.home_container {
    height: 100%;
    overflow: hidden;
}

/* 头部的样式 */
.el-header {
    background-color: #373d41;
    display: flex;
    justify-content: space-between;
    padding-left: 0%;
    align-items: center;
    color: #ffffff;
    font-size: 20px;
    > div {
        display: flex;
        align-items: center;
        span {
            margin-left: 15px;
        }
    }
}

/* 侧边栏的样式 */
.el-aside {
    background-color: #333744;
    .el-menu {
        border-right: none;
    }
}

/* 主题的样式 */
.el-main {
    background-color: #eaedf1;
    height: 100%;
}
img {
    width: 55px;
    height: 55px;
}
/* 伸缩按钮 */

.toggle-button {
    background-color: #4a5064;
    font-size: 10px;
    line-height: 24px;
    color: #fff;
    text-align: center;
    letter-spacing: 0.2em;
    cursor: pointer;
}
</style>
